import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// svg图标
import viteSvgIcons  from 'vite-plugin-svg-icons';
// gzip压缩
import viteCompression from 'vite-plugin-compression';
// 按需引入组件
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'


import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // scg图标
    viteSvgIcons({
      // Specify the icon folder to be cached
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      svgoOptions:false,
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]',
    }),
    // 压缩
    // viteCompression({
    //   deleteOriginFile:true
    // }),
    Components({
      dts: true,
      dirs: ['src/components'], // 按需加载的文件夹
      resolvers: [ElementPlusResolver()] // ElementPlus按需加载
    })
  ],
  base: '/',//公共基础路径 打包路径
  envPrefix:'VUE_APP_',
  resolve: {
      alias: {
          "@/": `${path.resolve(__dirname, "src")}/`
      }
  },
  server: {
    open:true,
    // Listening on all local IPs
    host: true,
    port: 8888,//启动端口
    proxy: { // 代理配置
      '/api': {
            target: 'http://192.168.2.93:8080',//后端服务地址
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, '') // 重写路径
        }
    }
  },
})
